<template>
  <a-config-provider :locale="language">
    <RouterView :class="route.name" />
  </a-config-provider>
</template>
<script setup lang="ts">
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import { onMounted, onUnmounted, provide, ref } from 'vue'
import { RouterView, useRoute } from 'vue-router'
import { useUserInfoStore } from './stores/modules/userInfo'
// import { getUserInfo } from './api/user'
import { useChatBus } from '@/hook/useChatBus'
import {  ROUTER_WHITE_LIST } from '@/config' 
const route = useRoute()
const language = ref(zhCN)
const userInfoStore = useUserInfoStore()
const interval = ref<number | null>(null)

const setIntervalValue = () => {
  if(!interval.value && !ROUTER_WHITE_LIST.includes(route.name as string) ) {
    interval.value = setInterval(async() => {
      // getUserInfo()
      await userInfoStore.setUserInfo()
    }, 60000)
  }
}
provide('setIntervalValue',setIntervalValue)


const clearIntervalValue = () => {
  console.warn('清除了定时器');
  clearInterval(Number(interval.value))
}

useChatBus((e) => {
  switch (e) {
    case 'clearIntervalValue':
    clearIntervalValue()
      break
    default:
      ''
  }
})



onMounted(() => {
  if(userInfoStore.frontToken) {
    clearInterval(Number(interval.value))
    setIntervalValue()
  }
})
onUnmounted(() => {
  clearInterval(Number(interval.value))
})
</script>
<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}
::v-deep .ant-layout-sider{
  z-index: 2;
}
</style>
